package scaladuct.l10n

import java.util.{Locale, ResourceBundle}
import scaladuct.{Extensible, ConfigPage, ConfigPageGateway}

/**
 * <p>
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Feb 7, 2011
 * Time: 9:21:36 PM
 */
trait DecoratingMetaDataSource extends HasHintsMetaDataSource {
  val decoratedPage: Extensible
  val extendingBundleName: String
  val extendingBundlePrefix: String

  def configPageMetaData(locale: Locale): Option[HasHintsMetaData] = {
    val bundle: ResourceBundle = ResourceBundle.getBundle(extendingBundleName, locale)
    val myMetaData = new ResourceBundleHasHintsMetaData(bundle, extendingBundlePrefix)
    decoratedPage.extension(classOf[HasHintsMetaDataSource]) match {
      case Some(pageMetaDataSource) => {
        pageMetaDataSource.configPageMetaData(locale) match {
          case Some(pageMetaData) => Some(new DuplexHasHintsMetaData(bundle.getLocale, pageMetaData, myMetaData))
          case None => Some(myMetaData)
        }

      }
      case None => Some(myMetaData)
    }
  }

}